package com.xblibo.xruth.web;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * <p>Title: ServletContextLoaderListener.java </p>
 * <p>Description:  </p>
 * <p>Copyright: 易宝 2011*版权所有 </p>
 * <p>Company: yeepay </p>
 * @author xblibo
 * @version 1.0 ,  2011  下午03:38:08
 */
public class ServletContextLoaderListener implements ServletContextListener{
	
	/**
	 * 初始化监听器（应用启动），把应用需要的一些固定信息缓存起来
	 */
	 public void contextInitialized(ServletContextEvent servletContextEvent) {  
        //ServletContext servletContext = servletContextEvent.getServletContext();  
        //SecurityManager securityManager = this.getSecurityManager(servletContext);  
          
        //Map<String, String> urlAuthorities = securityManager.loadUrlAuthorities();  
        //servletContext.setAttribute("urlAuthorities", urlAuthorities);  
	  }  
	 
	 /**
	  * 销毁监听器 （应用关闭时）
	  */
	 public void contextDestroyed(ServletContextEvent servletContextEvent) {  
	        servletContextEvent.getServletContext().removeAttribute("urlAuthorities");  
	    }  
	 
	 
	 protected SecurityManager getSecurityManager(ServletContext servletContext) {  
	       return (SecurityManager) WebApplicationContextUtils.getWebApplicationContext(servletContext).getBean("securityManager");   
	    }

	
}
